﻿using Com.FastSearch.Esp.Search.View;
using Com.FastSearch.SharePoint.Interfaces;

namespace Com.FastSearch.SharePoint.BL.SearchManager
{
    /// <summary>
    /// Implementation of the <see cref="IESPNavigatorDefinition"/> interface,
    /// that uses navigators from the Search API.
    /// </summary>
    public class ESPNavigatorDefinition : IESPNavigatorDefinition
    {
        private readonly string name;
        private readonly string displayName;
        private readonly bool isScopeNavigator;
        private string scope;

        /// <summary>
        /// Create a navigator definition based on the given navigator from the
        /// Search API.
        /// </summary>
        /// <param name="navigator">the navigator object from the search api</param>
        public ESPNavigatorDefinition(INavigator navigator)
            : this(navigator.Name, navigator.DisplayName, navigator.FieldRef.IsScope())
        {
        }

        /// <summary>
        /// Create a navigator definition with the given values.
        /// </summary>
        /// <param name="name">the internal name of the navigator</param>
        /// <param name="displayName">the name of the navigator that should be shown to the user</param>
        /// <param name="isScopeNavigator">whether the navigator is a scope-navigator, that aggregates over XML instead of flat fields</param>
        public ESPNavigatorDefinition(string name, string displayName, bool isScopeNavigator)
        {
            this.displayName = displayName;
            this.isScopeNavigator = isScopeNavigator;
            this.name = name;
        }

        #region IESPNavigatorDefinition Members

        /// <inheritdoc/>
        public string Name
        {
            get { return name; }
        }

        /// <inheritdoc/>
        public string DisplayName
        {
            get { return displayName; }
        }

        /// <inheritdoc/>
        public bool IsScopeNavigator
        {
            get { return isScopeNavigator; }
        }

        /// <inheritdoc/>
        public string Scope
        {
            get { return IsScopeNavigator ? scope : null; }
            set { scope = value; }
        }

        #endregion
    }
}
